﻿package 
{
	import core.StageCanvas;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author hippiman
	 */
	[SWF(width = "1000", height = "700", frameRate="120", backgroundColor="#FFFFFF")]
	public class Main extends StageCanvas
	{	
		private var tf:TextField;
		[Embed(source="assets/times.ttf", fontFamily="Times")]
		private var timesFont:Class;
		public function Main():void {
			tf = addChild(new TextField()) as TextField;
			tf.embedFonts = true;
			tf.selectable = false;
			tf.text = "Hello, world?";
			tf.setTextFormat(new TextFormat("Times", 10, 0xFF))
			tf.width = tf.textWidth + 5;
			tf.height = tf.textHeight + 5;
			addEventListener(Event.ENTER_FRAME, enterFrame);
		}
		private function enterFrame(e:Event):void {
			var xPos:Number = stage.mouseX - tf.width / 2;
			var yPos:Number = stage.mouseY - tf.height / 2;
			var angle:Number = Math.atan2((yPos - tf.y), (xPos - tf.x));
			var distance:Number = Math.sqrt(Math.pow(xPos - tf.x, 2) + Math.pow(yPos - tf.y, 2));
			tf.x += Math.cos(angle) * distance / 4;
			tf.y += Math.sin(angle) * distance / 4;
			tf.rotation += 1;
		}
	}
	
}